<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

require_once 'AIR2_CRUD_Controller.php';

/**
 * Tag Controller
 *
 * @author rcavis
 * @package default
 */
class Tag_Controller extends AIR2_CRUD_Controller {
    /* AIR2_CRUD_Controller variables */
    public $base_model_name = 'TagMaster';
    public $base_view_name  = 'tagmaster';
    public $exposed_relations = array();
    public $autoload_relations = array();
    public $column_blacklist = array();
    public $column_whitelist = array();
    public $taggable = false; // tagging tags?  Oh, my head!


    /**
     * Add custom relations to queries to this controller
     *
     * @param AIR2_Query $q
     * @param boolean $deeply (optional)
     */
    protected function _add_query_load_related(&$q, $deeply=true) {
        if (!$this->rel_uri) { // base TagMaster level
            $usage = 'select COUNT(*) from tag where tag_tm_id = a.tm_id';
            $q->select("a.*, m.*, ($usage) as usage");
            $q->leftJoin('a.IptcMaster m');
            $q->orderBy('usage DESC');
            $q->limit(8);
            $this->extra_field_defs []= array('name' => 'usage', 'type' => 'int');
        }

        parent::_add_query_load_related($q, $deeply);
    }


}
